package cn.trigram.lang.ary;

public class HexUtil {

  public final static char[] HEX_CHARS =
      {'0', '1', '2', '3', '4', '5', '6', '7',
          '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

  public static char[] toHexChars(byte[] bs) {

    char[] chs = new char[bs.length * 2];
    for (int i = 0; i < bs.length; i++) {
      byte b = bs[i];
      byte[] temp = new byte[1];
      temp[0] = b;
      temp[0] >>>= 4;
      temp[0] &= 0b0000_1111;
      chs[i * 2] = HEX_CHARS[temp[0]];

      temp[0] = b;
      temp[0] &= 0b0000_1111;
      chs[i * 2 + 1] = HEX_CHARS[temp[0]];
    }
    return chs;
  }

}
